﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1.DesignerPatter.Test
{
    class TestMain
    {
        static void Main()
        {
            Cat c = new Cat("Tom");
            Mouse m = new Mouse("Jack");
            Mouse m1 = new Mouse("Jerry");
            //c.CatShout += new Cat.CatShoutEventHandle(m1.Run);
            //c.CatShout +=new Cat.CatShoutEventHandle(m.Run);
            c.Shout();

            Cat c1 = new Cat("Tom1");
            c1.CatShout += new Cat.CatShoutEventHandle(m.Run);
            c1.Shout();

            Console.Read();
        }
    }

    class CatShoutEventArgs:EventArgs
    {
        private string name;
        public string GetName
        {
            get { return name; }
            set { name = value; }
        }
    }

    class Cat
    {
        private string  name;
        public delegate void CatShoutEventHandle(object sender,CatShoutEventArgs args);
        public event CatShoutEventHandle  CatShout;

        public Cat(string name)
        {
            this.name = name;
        }

        public void Shout()
        {
            Console.WriteLine("喵，我是{0}",name);
            if (CatShout != null)
            {
                CatShoutEventArgs e = new CatShoutEventArgs();
                e.GetName = name;
                CatShout(this, e);
            }
        }
    }

    class Mouse
    {
        private string name;
        public Mouse(string name)
        {
            this.name = name;
        }

        public void Run(object sender,CatShoutEventArgs args)
        {
            Console.WriteLine("老猫{0}来了，{1}快跑",args.GetName,name);
        }
    }
}
